package com.sll.hosptials.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.ResponseMessage;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.List;

/**
 * Swagger配置类
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    //http://192.168.2.116:27412/qyfxjc/doc.html
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.OAS_30)
                .groupName("Web")
                .apiInfo(apiInfo()).enable(true)
                .select()
                //apis： 添加swagger接口提取范围
                .apis(RequestHandlerSelectors.basePackage("com.sll.hosptials.controller"))
                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
//                .paths(PathSelectors.ant("/consultingmanagement-dev/web/**"))
                .paths(PathSelectors.any())
                .build();
//                .securitySchemes(securitySchemes())
//                .securityContexts(securityContexts());
    }


    /** 设置授权信息 */
//    private List securitySchemes() {
//        ApiKey apiKey = new ApiKey("token", "token", In.HEADER.toValue());
//        return Collections.singletonList(apiKey);
//    }
//
//    /** 授权信息全局应用 */
//    private List securityContexts() {
//        return Collections.singletonList(
//                SecurityContext.builder()
//                        .securityReferences(
//                                Collections.singletonList(
//                                        new SecurityReference(
//                                                "token",
//                                                new AuthorizationScope[] {new AuthorizationScope("global", "")})))
//                        .build());
//    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("接口文档")
                .description("接口文档")
                .contact(new Contact("", "", ""))
                .version("1.0")
                .build();
    }
}
